﻿    var bon = "images/button_4.png";
    var gon = "images/button_3.png";
    var ron = "images/button_2.png";
    var yon = "images/button_1.png";
    var width = 18;
    var height = 18;
   function init()
    {
        ondock();
        System.Gadget.onDock = ondock;
        System.Gadget.onUndock = ondock;
        System.Gadget.settingsUI = "settings.html";
        settime();
		    
	}

    function settime()
    {
        var curtime = new Date();
        var time = new Array();

        time[0] = parseInt((curtime.getFullYear()-2000)%Math.pow(64, 1));
        time[1] = curtime.getMonth()+1;
        time[2] = curtime.getDate();
        time[3] = curtime.getHours();
		var twelve = System.Gadget.Settings.read("twelve");
		if(twelve != '' && time[3] > 12)
		{
		   time[3] = time[3] - 12;
		}
		time[4] = curtime.getMinutes();
		time[5] = curtime.getSeconds();
		  
        for(i=5; i>=0; i--) 
        {
             for(j=2;j >=0; j--) 
             {
                 display("" + i + j, parseInt(time[i] / Math.pow(4, j)));
                 time[i] = time[i] % Math.pow( 4, j);
             }    
        }     
		setTimeout("settime()",1000);
    }
    
    function display(index, lon)
    {
        if(lon == 3)
        {
            document.all(index).src = bon;
        }
        else if(lon == 2)
        {
            document.all(index).src = gon;
        }
        else if(lon == 1)
        {
            document.all(index).src = yon;
        }
        else
        {
            document.all(index).src = ron;
        }
    }
    function ondock()
    {
        if(System.Gadget.docked)
        {
            document.body.style.backgroundImage = "url(../images/BackBlue_Docked.png)";
            width = 18;
            height = 18;
        }
        else
        {
            document.body.style.backgroundImage = "url(../images/BackBlue_Undocked.png)";
            width = 36;
            height = 36;
        }
        resize();
    }
    
    function resize()
    {
        var imgs = document.getElementsByTagName("img");
        for(i=0; i<imgs.length; i++)
        {
           imgs[i].style.width = width;
           imgs[i].style.height = height;
        }
        if(System.Gadget.docked)
        {
            document.body.style.width = 128;
            document.body.style.height = 75;
        }
        else
        {
            document.body.style.width = 256;
            document.body.style.height = 150;
        }
        document.body.style.margin = width / 2;
    }